<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>课程列表</title>
    <script src="/jquery/jquery-3.2.1.min.js"></script>
    <script src="/layui/layui.js"></script>
    <link rel="stylesheet" href="/layui/css/layui.css">
    <!-- 导入Ztree -->
    <link rel="stylesheet" href="/ztree/css/metroStyle/metroStyle.css"/>
    <script type="text/javascript" src="/ztree/js/jquery.ztree.all.min.js"></script>
    <!-- 基本功能 -->
    <script type="text/javascript" src="/ztree/js/jquery.ztree.core.js"></script>
    <!-- 复选功能 -->
    <script type="text/javascript" src="/ztree/js/jquery.ztree.excheck.js"></script>
    <!-- 编辑功能 -->
    <script type="text/javascript" src="/ztree/js/jquery.ztree.exedit.js"></script>

    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .box{
            width: 100%;
            height: 1700px;
        }
        .box-table{
            width: 1670px;
            height: 900px;
        }
        .table-right{
            width: 1670px;
            height: 800px;
        }
        .list{
            width: 1650px;
            height: 50px;
            margin-left: 20px;
            background-color:rgb(243,243,243);
        }
        .list-left{
            width: 100px;
            height: 30px;
            margin-top: 10px;
            float: left;
        }
        .list-left-left{
            width: 10px;
            height: 30px;
            float: left;
            background: green;
        }
        .list-left-right{
            width: 80px;
            height: 30px;
            font-size: 14px;
            line-height: 30px;
            float: left;
            text-indent: 5px;
        }
        .list-right{
            float: right;
            margin-top: 5px;
            margin-right: 35px;
        }

        .box-btngroup{
            height: 50px;
            width: 1320px;
            margin-top: 25px;
        }
        .query{
            height: 50px;
            width: 1650px;
            background-color:rgb(243,243,243);
            margin: 30px 0 10px 20px;
        }
        .query .backColor div{
            float: right;
            margin-left: 70px;
        }
        .search{
            height: 30px;
            width: 1630px;
        }
        .search .layui-form .layui-form-item .layui-input-inline{
            height: 30px;
            width: 200px;
        }
        .search .layui-form .layui-form-item button{
            margin-right: 7px;
            float: right;
        }
        #chongzhi{
            margin-right: -133px;
        }

        #button_ids{
            height: 50px;
            width: 1670px;
            line-height: 50px;
            background-color:rgb(243,243,243);
        }
        #button_ids .layui-icon-align-left{
            margin-left: 20px;
        }
        #button_ids button{
            float: right;
            margin-right: 45px;
        }

        .record{
            width: 1650px;
            height: 1500px;
            margin-left: 20px;
            margin-top: 25px;
            background-color:rgb(243,243,243);
        }
        .record .tree-left{
            width: 300px;
            height: 300px;
            float: left;
        }
        .record .record-right{
            width: 1330px;
            height: 500px;
            margin-left: 20px;
            float: right;
        }

        div#rMenu {
            position:absolute;
            visibility:hidden;
            top:0;
            background-color: #555;
            text-align: left;
            padding: 2px;
        }
        div#rMenu ul li {
            margin: 1px 0;
            padding: 0 5px;
            cursor: pointer;
            list-style: none outside none;
            background-color: #DFDFDF;
        }
        /* height : 继承父元素高度 给layuitable*/
        .layui-table-cell {
            line-height: 47px;
            height: inherit;
        }
        .layui-table-cell>a{
            color:green;
        }
        .layui-form-item span button{
            margin-left: 150px;
        }
    </style>
</head>
<body>
<div class="box">
    <!-- 课程列表 -->
    <div class="list">
        <div class="list-left">
            <div class="list-left-left"></div>
            <p class="list-left-right">课程管理</p>
        </div>
        <div class="list-right">
            <div class="list-right-left layui-btn layui-icon layui-icon-refresh" onclick="refreshs()">&nbsp;刷新</div>
            <div class="list-right-right layui-btn layui-icon layui-icon-left" id="goBack">&nbsp;返回</div>
        </div>
    </div>
    <div class="box-table">
        <div class="table-right">
            <!-- 筛选查询 -->
            <div class="layui-row query">
                <div class="layui-card-header backColor">
                    <i class="layui-icon">&#xe615;</i>
                    筛选查询
                    <div class="query-top-right layui-btn" onclick="retrieval()" id="retrieval" style="margin-right:18px; margin-top: 5px;">高级检索</div>
                </div>
            </div>
            <!-- 搜索 -->
            <div class="layui-card-body search">
                <form class="layui-form">
                    <div class="layui-form-item">
                        <label class="layui-form-label">输入搜索：</label>
                        <div class="layui-input-inline" style="margin-right: 150px;">
                            <input type="text" name="courseName" id="courseName" required lay-verify="required" placeholder="请输入课程名称" autocomplete="off" class="layui-input">
                        </div>
                        <label class="layui-form-label">课程分类：</label>
                        <div class="layui-input-inline" style="margin-right: 150px;">
                            <select class="layui-select" name="name" id="className">
                                <option value=""></option>
                            </select>
                        </div>
                        <label class="layui-form-label">课程价格：</label>
                        <div class="layui-input-inline">
                            <input type="text" name="courseNprice" id="courseNprice" required lay-verify="required" autocomplete="off" class="layui-input" placeholder="请输入课程价格">
                        </div>
                        <span>
                            <button type="reset" class="layui-btn layui-btn-warm">
                                <i class="layui-icon layui-icon-refresh"></i> 重置
                            </button>
                            <button type="button" class="layui-btn" onclick="search()" id="chongzhi">
                                <i class="layui-icon layui-icon-search"></i> 搜索
                            </button>
                        </span>
                    </div>
                </form>
            </div>
            <!--表头样式 -->
            <div id="button_ids" style="display: none;">
                <i class="layui-icon layui-icon-align-left"></i> 数据列表

                <button type="button" class="layui-btn" onclick="addButton()" style="float: right;">
                    <i class="layui-icon">&#xe608;</i>添加
                </button>
                <button type="button" class="layui-btn import" onclick="leading()" style="margin-right: 20px; float: right;">
                    <i class="layui-icon">&#xe62f;</i>导入
                </button>
            </div>
            <!--数据列表-->
            <div class="record">
                <div class="record-right">
                    <!--表-->
                    <table id="demoTable" lay-filter="demoTable"></table>
                </div>
                <div class="tree-left">
                    <!--树-->
                    <ul id="treeDemo" class="ztree" style="margin-top: 20px;margin-left: 40px"></ul>
                </div>
            </div>
        </div>

        <!--表内操作-->
        <div id="button_caozuo" style="display:none">
            <a alt="查看" title="查看"  lay-event="selectTable">查看</a>
            <a alt="编辑" title="编辑"  lay-event="updateTable">编辑</a>
            <br/>
            <a alt="日志" title="日志"  lay-event="journalTable">日志</a>
            <a alt="删除" title="删除"  lay-event="deleteTable">删除</a>
        </div>
    </div>

    <!--ztree节点增删改-->
    <div id="rMenu">
        <ul>
            <li id="m_add" onclick="addTreeNode();">增加节点</li>
            <li id="m_del" onclick="removeTreeNode();">删除节点</li>
            <li id="m_edit" onclick="edit();">编辑节点</li>
        </ul>
    </div>
</div>
<!-- 高级检索 -->
<input type="hidden" name="ProductRetrieval" id="ProductRetrieval"/>

<!-- 返回 -->
<p id="title" style="display: none;">课程列表</p>
</body>
    <script>
        layui.use(['jquery','layer','table','form'],function(){
            var $=layui.jquery;
            var layer=layui.layer;
            var table=layui.table;
            var form=layui.form;

            var createTime = "";
            var updateDate = "";
            demoZtree();

            //刷新
            refreshs = function refreshs(){
                location.reload();
            }

            //返回
            $('#goBack').click(function () {
                var title = $('#title').text();
                var iframe = parent.$('.iframe');
                $.each(iframe,function (i,item) {
                    if(title == $(item).attr('_href')){
                        parent.$('#beforeHref').val($(item).attr('_href'));
                        parent.beforeHref();
                        return;
                    }
                });
            });

            //权限设置
            judge();
            function judge(){
                var user = localStorage.getItem('user');
                user = JSON.parse(user);
                var userId = user.data.userId;
                $.ajax({
                    url: '/product/judgePower',
                    type: 'post',
                    dataType: 'json',
                    data: {'id':userId},
                    success: function (data) {
                        if(data.data == 0){
                            demoZtree();
                        }else{
                            demoZtreeOther();
                        }
                    }
                })
            }
            //权限树
            function demoZtreeOther(){
                var setting = {
                    data: {
                        simpleData: {
                            enable: true,  //true 、 false 分别表示 使用 、 不使用 简单数据模式
                            idKey: "id",  //节点数据中保存唯一标识的属性名称
                            pIdKey: "parnetId",    //节点数据中保存其父节点唯一标识的属性名称
                            rootPId: -1  //用于修正根节点父节点数据，即 pIdKey 指定的属性值
                        },
                        key: {
                            name: "name"  //zTree 节点数据保存节点名称的属性名称  默认值："name"
                        }
                    },
                    view: {
                        dblClickExpand: false
                    },
                    check: {
                        enable : false,  //true 、 false 分别表示 显示 、不显示 复选框或单选框
                        nocheckInherit:true,  //当父节点设置 nocheck = true 时，设置子节点是否自动继承 nocheck = true
                        radioType: "all"
                    },
                    callback: {
                        onClick:zTreeOnClick //点击树节点展示对应table信息
                    }
                };

                //点击节点，展示对应类别下课程信息
                function zTreeOnClick() {
                    var nodes = zTree.getSelectedNodes();
                    var node = nodes[0];
                    id = node.id;
                    if(!node.isParent){
                        $.ajax({
                            url: '/course/getCheckedCourse',
                            type: 'post',
                            dataType: 'json',
                            data: {'classId' : id},
                            success: function (data) {
                                demoTable(data.data);
                            }
                        })
                    }else{
                        layer.msg("请选择最小分类类别");
                    }
                }

                //加载树
                var zTree, rMenu;
                $(document).ready(function(){
                    $.ajax({
                        url: '/course/getCourseTree',
                        type: 'post',
                        dataType: 'json',
                        success: function (data) {
                            zTree = $.fn.zTree.init($("#treeDemo"), setting, data.data);//初始化树
                            zTree.expandAll(true);    //true 节点全部展开、false节点收缩
                        }
                    })
                    rMenu = $("#rMenu");
                });

            };

            //Ztree树
            function demoZtree(){
                var setting = {
                    data: {
                        simpleData: {
                            enable: true,  //true 、 false 分别表示 使用 、 不使用 简单数据模式
                            idKey: "id",  //节点数据中保存唯一标识的属性名称
                            pIdKey: "parnetId",    //节点数据中保存其父节点唯一标识的属性名称
                            rootPId: -1  //用于修正根节点父节点数据，即 pIdKey 指定的属性值
                        },
                        key: {
                            name: "name"  //zTree 节点数据保存节点名称的属性名称  默认值："name"
                        }
                    },
                    view: {
                        dblClickExpand: false
                    },
                    check: {
                        enable : false,  //true 、 false 分别表示 显示 、不显示 复选框或单选框
                        nocheckInherit:true  //当父节点设置 nocheck = true 时，设置子节点是否自动继承 nocheck = true
                    },
                    callback: {
                        onRightClick: OnRightClick,
                        beforeRename: beforeRename,
                        onClick:zTreeOnClick //点击树节点展示对应table信息
                    }
                };
                //加载树
                var zTree, rMenu;
                $(document).ready(function(){
                    $.ajax({
                        url: '/course/getCourseTree',
                        type: 'post',
                        dataType: 'json',
                        success: function (data) {
                            zTree = $.fn.zTree.init($("#treeDemo"), setting, data.data);//初始化树
                            zTree.expandAll(true);    //true 节点全部展开、false节点收缩
                        }
                    })
                    rMenu = $("#rMenu");
                });

                function OnRightClick(event, treeId, treeNode) {
                    if (!treeNode && event.target.tagName.toLowerCase() != "button" && $(event.target).parents("a").length == 0) {
                        zTree.cancelSelectedNode();
                        showRMenu("root", event.clientX, event.clientY);
                    } else if (treeNode && !treeNode.noR) {
                        zTree.selectNode(treeNode);
                        showRMenu("node", event.clientX, event.clientY);
                    }
                }
                //修改前判断
                function beforeRename(treeId, treeNode, newName) {
                    if (newName.length == 0) {
                        alert("节点名称不能为空.");
                        var zTree = $.fn.zTree.getZTreeObj("treeDemo");
                        setTimeout(function(){zTree.editName(treeNode)}, 10);
                        return false;
                    }
                    return true;
                }
                function showRMenu(type, x, y) {
                    $("#rMenu ul").show();
                    if (type=="root") {
                        $("#m_del").hide();
                    } else {
                        $("#m_del").show();
                    }

                    y += document.body.scrollTop;
                    x += document.body.scrollLeft;
                    rMenu.css({"top":y+"px", "left":x+"px", "visibility":"visible"});

                    $("body").bind("mousedown", onBodyMouseDown);
                }

                function hideRMenu() {
                    if (rMenu) rMenu.css({"visibility": "hidden"});
                    $("body").unbind("mousedown", onBodyMouseDown);
                }
                function onBodyMouseDown(event){
                    if (!(event.target.id == "rMenu" || $(event.target).parents("#rMenu").length>0)) {
                        rMenu.css({"visibility" : "hidden"});
                    }
                }
                //添加树节点
                addTreeNode = function addTreeNode() {
                    hideRMenu();
                    var nodes = zTree.getSelectedNodes(); //获取选中节点的所有数据
                    var parnetId = nodes[0].id; //添加节点当前树节点的id，作为添加数据的父节点
                    layer.open({
                        type:1,
                        title:"添加节点",
                        area:['400px','220px'],
                        shade:0.4,
                        offset:['250px','650px'],
                        content:"<form class='layui-form'><div class='layui-form-item' style='margin: 20px;'>"+
                            "<label class='layui-input-label'>添加分类：</label>"
                            +"<div class='layui-input-block'>"
                            +"<input type='text' name='name' style='width:220px;height:30px;'id='addNode' lay-verify='required' placeholder='课程分类'>"
                            +"</div>"+"</div></form>",
                        btn:['添加','取消'],
                        yes:function () {
                            var name = $("#addNode").val();
                            if(name.length != 0){
                                $.ajax({
                                    url: '/course/addCourseTreeNode',
                                    type: 'post',
                                    dataType: 'json',
                                    data: {'name':name,'parnetId':parnetId},
                                    success: function (data) {
                                        if(data.data){
                                            location.reload();
                                        }
                                    }
                                })
                            }else {
                                layer.msg("分类名不能为空");
                            }
                        }
                    })
                }

                //删除树节点
                removeTreeNode = function removeTreeNode() {
                    hideRMenu();
                    var nodes = zTree.getSelectedNodes();
                    var node = nodes[0];
                    var id = nodes[0].id;
                    layer.confirm('确认要删除吗?', {icon: 3, title:'提示'}, function(index){
                        if(!node.isParent){
                            if (nodes && nodes.length>0) {
                                $.ajax({
                                    url: '/course/delCourseTreeNode',
                                    type: 'post',
                                    dataType: 'json',
                                    data: {'id':id},
                                    /*beforeSend: function () {
                                        if (nodes[0].children && nodes[0].children.length > 0){
                                            return confirm("要删除的节点是父节点，如果删除将连同子节点一起删掉。请确认？")
                                        }else {
                                            return confirm("确认删除？")
                                        }
                                    },*/
                                    success: function (data) {
                                        if(data.data){
                                            zTree.removeNode(nodes[0]);
                                            layer.msg("删除成功")
                                        }
                                    }
                                })
                            }
                        }else{
                            alert("请选择最小的子节点");
                        }
                    })

                }

                //修改树节点
                edit = function edit() {
                    hideRMenu();
                    var nodes = zTree.getSelectedNodes();
                    var id = nodes[0].id;
                    layer.open({
                        type:1,
                        title:"修改节点",
                        area:['400px','220px'],
                        shade:0.4,
                        offset:['250px','650px'],
                        content:"<form class='layui-form'><div class='layui-form-item' style='margin: 20px;'>"+
                            "<label class='layui-input-label'>修改分类：</label>"
                            +"<div class='layui-input-block'>"
                            +"<input type='text' name='name' style='width:220px;height:30px;'id='updateNode' lay-verify='required' placeholder='课程分类'>"
                            +"</div>"+"</div></form>",
                        btn:['修改','取消'],
                        yes:function () {
                            var name = $("#updateNode").val();
                            if(name.length != 0){
                                $.ajax({
                                    url: '/course/editCourseTreeNode',
                                    type: 'post',
                                    dataType: 'json',
                                    data: {'name':name,'id':id},
                                    success: function (data) {
                                        if(data.data){
                                            location.reload();
                                        }
                                    }
                                })
                            }else {
                                layer.msg("分类名不能为空");
                            }
                        }
                    })
                }

                //点击节点，展示对应类别下课程信息
                function zTreeOnClick() {
                    var nodes = zTree.getSelectedNodes();
                    var node = nodes[0];
                    id = node.id;
                    if(!node.isParent){
                        $.ajax({
                            url: '/course/getCheckedCourse',
                            type: 'post',
                            dataType: 'json',
                            data: {'classId' : id},
                            success: function (data) {
                                demoTable(data.data);
                            }
                        })
                    }else{
                        layer.msg("请选择最小分类类别");
                    }
                }

            }

            //表格 所有数据
            getTable();

            function getTable(){
                $.ajax({
                    url:"/course/getCourseTableByResult",
                    data:{"result": 1},
                    type:"post",
                    dataType:"json",
                    success:function (data) {
                        demoTable(data.data);
                    }
                })
            }

            function demoTable(data){
                var tableRender = table.render({
                    elem:'#demoTable',
                    title:"课程",
                    data:data,
                    toolbar:'#button_ids',
                    limit:10,
                    width:1320,
                    page:{
                        layout:['count','prev','page','next','limit','skip','refresh'],
                        limits:[10,20,30],
                        first:"首页",
                        last:"尾页",
                    },
                    cols:[[
                        {type:'checkbox'},
                        {field:"",title:"序号",align:'center',width:60,templet: function(data){
                                return data.LAY_INDEX;
                            }},
                        {field:"url",title:"课程图片",align:'center',width:150,style: "height:116px;",templet:function(data){
                                return '<img src="'+data.url+'"/>';
                            }},
                        {field:"courseName",title:"课程名称",align:'center',width:150},
                        {field:"trueName",title:"上传人",align:'center',width:125},
                        {field:"courseNprice",title:"课程价格",align:'center',width:125,templet:function(data){
                                return '<p>￥'+data.courseNprice+'</p>';
                            }},
                        {field:"courseStatus",title:"状态",align:'center',width:125,templet:function(data){
                                if(data.courseStatus==2){
                                    return '<input type=\"checkbox\" value="'+data.courseId+'" lay-skin=\"switch\" lay-text=\"上架|下架"\ checked lay-filter="switchTest">';
                                }else if(data.courseStatus==3){
                                    return '<input type=\"checkbox\" value="'+data.courseId+'" lay-skin=\"switch\" lay-text=\"上架|下架" lay-filter="switchTest"\>';
                                }else if(data.courseStatus==4){
                                    return '<p>已删除</p>';
                                }
                            }},
                        {field:"name",title:"课程分类",align:'center',width:125},
                        {field:"saleNum",title:"销量",align:'center',width:125,templet:function(data){
                            if(data.saleNum==null){
                                return 0;
                            }else {
                                return data.saleNum;
                            }
                        }},
                        {field:"result",title:"审核状态",align:'center',width:125,templet:function(data){
                                var result;
                                if(data.result==1){
                                    result = "审核通过";
                                }else if(data.result == 2){
                                    result = "待审核";
                                }else if(data.result == 3){
                                    result = "审核失败";
                                }
                                // return '<p>'+result+'</p><a href="javascript:auditDetails();" style="color: #00B83F;">审核详情</a>';
                                return  '<p>'+result+'</p><a href="javascript:auditDetails('+data.courseId+');" style="color: #00B83F;" >审核详情</a>';
                            }},
                        {field:'',title:"操作",align:'center',width:150,toolbar:'#button_caozuo'}
                    ]]
                })

                //审核详情
                auditDetails = function  auditDetails(courseId){
                    localStorage.setItem("courseId",courseId);
                    layer.open({
                        type:2,
                        title:"审核详情",
                        area:["1000px","500px"],
                        offset:"auto",
                        shade:0.4,
                        content:"/curriculum/courselist/course-audit-details.html",
                        btn:['确定','取消'],
                        yes:function( index,layero){
                            layer.close(index);
                        },
                        btn2:function(index,layero){
                            layer.close(index);
                        }

                    })
                }

                //右边工具栏监听
                table.on('tool(demoTable)',function (obj) {
                    localStorage.setItem("courseData",JSON.stringify(obj.data));
                    var event = obj.event;
                    if (event == "selectTable"){
                        var dictValue = "查看";
                        getTime();
                        var editar = {
                            'logType':2,
                            "type":5,
                            "userId":obj.data.createId,
                            'createDate':createTime,
                            'remark':'查看反馈统计',
                        }
                        $.ajax({
                            url:"/JsLog/addProductJsLog",
                            data:editar,
                            type:'post',
                            dataType:'text',
                            success:function (data) {
                            }
                        });
                        layer.open({
                            type:2,
                            title:"查看",
                            area:["95%","99%"],
                            offset:'auto',
                            btn:["确定","取消"],
                            content:"course-list-tool-select.html",
                            success:function(layero,index){
                                var child = layero.find('iframe').contents();
                                child.find("#courseName").text(obj.data.courseName);
                                child.find("#createDate").text(obj.data.createDate);
                                child.find("#trueName").text(obj.data.trueName);
                                child.find("#courseNprice").text(obj.data.courseNprice);
                                child.find("#coursePrimary").text(obj.data.coursePrimary);
                                child.find("#className").text(obj.data.name);
                                if(obj.data.likeNum==null){
                                    child.find("#likeNum").text(0);
                                }else{
                                    child.find("#likeNum").text(obj.data.likeNum);
                                }
                                if(obj.data.collectNum==null){
                                    child.find("#collectNum").text(0);
                                }else{
                                    child.find("#collectNum").text(obj.data.collectNum);
                                }
                                child.find("#courseInfo").text(obj.data.courseInfo);
                                child.find("#courseIntro").text(obj.data.courseIntro);
                                child.find("#url").attr("src",obj.data.url);
                                child.find("#video").attr("src",obj.data.courseUrl);
                            },
                            yes:function( index,layero){
                                layer.close(index);
                            },
                            btn2:function(index,layero){
                                layer.close(index);
                            },
                            end:function (layero, index) {
                                layer.close(index);
                            }
                        });
                    }else if (event == "updateTable") {
                        var dictValue = "编辑";
                        getTime();
                        var editar = {
                            'logType':2,
                            "type":4,
                            "userId":obj.data.createId,
                            'createDate':createTime,
                            'remark':'编辑反馈统计',
                        }
                        $.ajax({//添加日志
                            url:"/JsLog/addProductJsLog",
                            data:editar,
                            type:'post',
                            dataType:'text',
                            success:function (data) {
                            }
                        });
                        layer.open({
                            type:2,
                            title:"修改",
                            area:["800px","600px"],
                            btn:["确定","取消"],
                            content:"course-list-tool-update.html",
                            yes:function( index,layero){
                                //获取子页面的所有内容
                                var child = layero.find('iframe').contents();
                                getTime();
                                var courseId = child.find("#courseId").val();
                                var courseName = child.find("#courseName").val();
                                var courseNprice = child.find("#courseNprice").val();
                                var coursePrice = child.find("#coursePrice").val();
                                var coursePrimary = child.find("#coursePrimary").val();
                                var courseInfo = child.find("#courseInfo").val();
                                var courseStatus = child.find("#courseStatus").val();
                                var param = {
                                    'courseId': courseId,
                                    'courseName':courseName,
                                    'courseNprice':courseNprice,
                                    'coursePrice':coursePrice,
                                    'coursePrimary':coursePrimary,
                                    'courseInfo':courseInfo,
                                    'courseStatus':courseStatus,
                                    'updateDate':updateDate,
                                    'updateId':JSON.parse(localStorage.getItem('user')).data.userId
                                }
                                $.ajax({//修改课程
                                    url:"/course/updateCourse",
                                    data:param,
                                    type:'post',
                                    dataType:'json',
                                    success:function (data) {
                                        if(obj.data.courseNprice!=courseNprice){
                                            getTime();
                                            var params={
                                                'dictLabel':obj.data.classId,//编号
                                                'dictValue':obj.data.courseName,//课程名
                                                'dictType':14,
                                                'cssClass':obj.data.courseNprice,//原价
                                                'listClass': courseNprice,//现价
                                                'createTime':createTime //修改时间
                                            }
                                            $.ajax({//添加修改价格日志
                                                url:"/SyDictData/addProductPrice",
                                                data:params,
                                                type:'post',
                                                dataType:'json',
                                                success:function (data) {
                                                }
                                            })
                                        }
                                        getTable();
                                    }
                                })
                                layer.close(index);
                            },
                            btn2:function(index,layero){
                                layer.close(index);
                            },
                            end:function () {
                                getTable();
                            }
                        });
                    }else if (event == "journalTable") {
                        var dictValue = "日志";
                        getTime();
                        var editar = {
                            'logType':2,
                            "type":1,
                            "userId":obj.data.createId,
                            'createDate':createTime,
                            'remark':'日志反馈统计',
                        }
                        $.ajax({
                            url:"/JsLog/addProductJsLog",
                            data:editar,
                            type:'post',
                            dataType:'text',
                            success:function (data) {
                            }
                        });
                        layer.open({
                            type: 2,
                            title: "日志",
                            area:["95%","100%"],
                            scrollbar: false,
                            offset:'auto',
                            btn:["确定","取消"],
                            content: "/curriculum/log/courseLog/course-log-open.html",
                            success:function(){
                            },
                            yes:function( index,layero){
                                layer.close(index);
                            },
                            btn2:function(index,layero){
                                layer.close(index);
                            },
                        });
                    }else if(event == "deleteTable") {
                        var courseId = obj.data.courseId;
                        layer.confirm('确认要删除吗?', {icon: 3, title:'提示'}, function(index){
                            getTime();
                            var editar = {
                                'logType':2,
                                "type":3,
                                "userId":obj.data.createId,
                                'createDate':createTime,
                                'remark':'删除反馈统计',
                            }
                            $.ajax({
                                url:"/JsLog/addProductJsLog",
                                data:editar,
                                type:'post',
                                dataType:'text',
                                success:function (data) {
                                }
                            });
                            $.ajax({//删除商品
                                url:"/course/delCourseByCourseId",
                                data:{'courseId' : courseId},
                                type:'post',
                                dataType:'json',
                                success:function (data) {
                                    $.ajax({//删除审核记录
                                        url:"/course/delCourseRecord",
                                        data:{'courseId': courseId},
                                        type:'post',
                                        dataType:'json',
                                        success:function (data) {
                                            //删除课程对应评论
                                            $.ajax({
                                                url:"/course/delCommentByCommodityId",
                                                data:{'courseId' : courseId},
                                                type:"post",
                                                dataType:"json",
                                                success:function(){

                                                }
                                            })
                                            layer.msg("删除成功");
                                        }
                                    })
                                    getTable();
                                }
                            });
                        });
                    }else {
                        console.log("为什么会点到我，好好反省反省！！！");
                    }
                })

            };

            //监听课程的上下架状态并修改状态
            form.on('switch(switchTest)', function(data){
                if(data.elem.checked==true){
                    $.ajax({
                        url:"/course/updateCourseStatus",
                        type:"post",
                        dataType:"json",
                        data:{'courseStatus':2,'courseId':data.value},
                        success:function (data) {
                            getTable();
                            layer.msg("修改成功");
                        }
                    })
                }else{
                    $.ajax({
                        url:"/course/updateCourseStatus",
                        type:"post",
                        dataType:"json",
                        data:{'courseStatus':3,'courseId':data.value},
                        success:function (data) {
                            getTable();
                            layer.msg("修改成功");
                        }
                    })
                }
            })

            //查询所有课程分类 给下拉框赋值
            $.ajax({
                url: '/course/getCourseClassAll',
                dataType: 'json',
                type: 'post',
                success: function (data) {
                    var syProductCategroys = data.data;
                    for (var i = 0; i < syProductCategroys.length; i++) {
                        $('#className').append('<option value="' + syProductCategroys[i].name + '" >' + syProductCategroys[i].name + '</option>')
                    }
                    form.render('select');//渲染到select标签
                }
            });

            //高级检索
            retrieval = function retrieval(){
                layer.open({
                    type : 2,
                    title : "高级检索",
                    area : [ '900px', '550px' ],
                    shade : 0,
                    offset: 'auto',
                    content :"/curriculum/courselist/course-sample.html",
                    btn:["确认","取消"],
                    yes:function(index,layero){
                        var child = layero.find('iframe').contents();
                        var courseId = child.find("input[name=courseId]").val();
                        var courseNprice = child.find("input[name=courseNprice]").val();
                        var name = child.find("#name option:selected").val();
                        var courseName = child.find("input[name=courseName]").val();
                        var coursePrimary = child.find("input[name=coursePrimary]").val();
                        var trueName = child.find("input[name=trueName]").val();
                        var param = {
                            'courseId': courseId,
                            'courseNprice': courseNprice,
                            'name': name,
                            'courseName': courseName,
                            'coursePrimary' : coursePrimary,
                            'trueName': trueName
                        }
                        $.ajax({
                            url:"/course/getCourseRetrieval",
                            data:param,
                            type:"post",
                            dataType:"json",
                            success:function (data) {
                                if(data!=null){
                                    demoTable(data.data);
                                }
                                layer.close(index);
                            }
                        })
                    },
                })
            }

            //导入excel表格
            leading=function leading(){
                layer.open({
                    type:2,
                    title:"上传文件",
                    area:["400px","300px"],
                    btn:["确定","取消"],
                    offset: 'auto',
                    content:"ExcelUpload.html",
                })
            }

            //课程的模糊查询
            getTableSearch = function getTableSearch(courseName,name,courseNprice){
                $.ajax({
                    url:"/course/getCourseSearch",
                    type:"post",
                    dataType:"json",
                    data:{'courseName':courseName,'name': name,'courseNprice':courseNprice},
                    success:function (data) {
                        demoTable(data.data);
                    }
                })
            };

            //搜索
            search = function search(){
                var courseName = $("#courseName").val();
                var name = $("#className").val();
                var courseNprice = $("#courseNprice").val();
                getTableSearch(courseName,name,courseNprice);
            }

            //添加课程 添加头部选项卡
            addButton = function addButton() {
                parent.$('#quickEntry').val("添加课程");
                parent.quickEntry();
            }


            //现在时间
            function getTime(){
                var date=new Date();
                var year=date.getFullYear();
                var month=date.getMonth()+1;
                var day=date.getDate();
                var hour=date.getHours();
                var minute=date.getMinutes();
                var second=date.getSeconds();
                var dateStr = year+"-"+zeroFilling(month)+"-"+zeroFilling(day)+" "+zeroFilling(hour)+":"+zeroFilling(minute)+":"+zeroFilling(second);
                updateDate = dateStr;
                createTime = dateStr;
            }
            function zeroFilling(data){
                if(data<10){
                    data="0"+data;
                }
                return data;
            }
        })
    </script>
</html>